Skip to content

Add animated video face for Turing 2.1" rev C (native video + live overlay) - #1150

Open
f4ww4z wants to merge 16 commits into
mathoudebine:mainfrom
f4ww4z:rev-c-video-face
Open

f4ww4z wants to merge 16 commits into
mathoudebine:mainfrom
f4ww4z:rev-c-video-face

Conversation

@f4ww4z

@f4ww4z f4ww4z commented Dec 2, 2026 •

Copy link
Copy Markdown

Depends on #1149. The first two commits of this branch are #1149 (the rev C partial-update framing fix). Once that merges, this PR's diff will contain only the commits after it. Happy to rebase.

Summary

This adds an optional animated "video face" for the Turing 2.1" round rev C screen. Instead of streaming animation frames over serial (a full 480×480 frame takes about 330 ms), it uses the screen's own storage and native H.264 playback:

  1. Background video: a seamless looping 480×480 video (glowing ring and sparkles) is generated procedurally with ffmpeg, uploaded once to the screen's storage (/root/video/), and played natively at about 30 fps.
  2. Live overlay: live stats are drawn as an overlay on top of the playing video. Only changed pixels are sent every 0.5 s, which takes about 10–50 ms per update.

The layout is CPU / GPU / RAM rows. Each row has a label, a history of bars centred on the row, and the value. Bar colours move from blue through yellow to red, with thresholds that can be configured.

What's added

Existing code paths are unchanged.

  • library/lcd/lcd_comm_rev_c_video.py: LcdCommRevCVideo, a subclass of LcdCommRevC. It handles storage commands (list, file size, upload, delete), play/stop, full overlay init, incremental overlay updates and status parsing (needReSend/renderCnt), with recovery.
  • library/video_face/: the app loop, the renderer, the sampler (through library/sensors, as selected by HW_SENSORS, so NVIDIA, AMD, Intel and LHM all work; a missing GPU shows "N/A"), settings and the video generator.
  • video-face-rev-c.py: a standalone entry point, alongside main.py and simple-program.py.
    • It doesn't use the theme scheduler, because it drives the device in video-overlay mode.
    • It can't run at the same time as main.py, since both use the serial port.
  • config.yaml: a new optional video_face: section (rows, sample period, remote dir/prefix, bar colours and thresholds). All keys have defaults. If the section is missing or malformed, library/config.py falls back to the defaults, so older configs and main.py are unaffected.
  • res/docs/rev-c-video-face.md and a preview GIF, plus a 2-line README entry.
  • Unit tests: tests/library/lcd/test_lcd_comm_rev_c_video.py and tests/library/video_face/test_video_face.py.

Robustness

  • Storage size: the screen's video storage holds only about 1.2 MB. The video is size-checked (1.1 MB guard, with a CRF ladder to fit) before anything is deleted or uploaded.
  • Serial errors: they trigger backoff, reconnect and an overlay re-init.
  • Upload failures: only a confirmed truncated upload (after one retry) exits with a fatal code.
  • Stalled playback: if renderCnt stalls, the video is replayed and re-uploaded if it has gone missing.
  • Exit codes:
    • 1: screen unreachable
    • 2: config / ffmpeg / size problem
    • 3: upload failed
  • Shutdown: stop requests (Ctrl-C / SIGTERM where available) are honoured during startup and between upload chunks.

Testing

  • Device: Turing 2.1" rev C, ROM 89, Linux, NVIDIA GPU.
    • Hours of runtime across iterations.
    • In the final runs: 0 failed updates and 0 recoveries, renderCnt about 29.5/s, overlay latency 10 ms on average.
    • Recovers after a forced kill.
  • Unit tests: python -m unittest discover -s tests -t . passes for all new tests. The 8 errors in tests/library/lcd/test_lcd_comm_rev_c.py already exist on main (see Fix rev C partial update framing and render count reset #1149).

Limitations / notes

  • Tested hardware: only the 2.1" (480×480, ROM 89). The app refuses to run unless the theme size is 2.1" and REVISION: C.
  • DISPLAY_REVERSE: false: the orientation for this setting is derived but not verified on a device. true was verified visually.
  • ffmpeg: required (install notes per OS are in the doc).
  • Credits: the protocol details build on the reverse engineering in Video support! #348 (video support) and in maylton/turing-smart-screen-video-overlay (GPL-3.0). Both are credited in the doc and module headers.
  • Splitting: this PR is larger than usual. I can split it into "driver subclass + tests" and "app + config + docs" if you prefer.

f4ww4z added 16 commits December 2, 2026 08:21
The display reads 249 data bytes from each 250-byte packet and treats the
last byte as a separator; the "ef69" terminator belongs to that data stream.
_generate_update_image chunked only the raw pixel records (and only when
longer than 250 bytes) and appended the terminator afterwards, so updates
whose length fell on certain residues (raw lengths 248/249 mod 249, and
248-250 unchunked) lost the terminator: the status reply was swallowed or
the display answered needReSend:1 to every later update.

Chunk the records and the terminator together. Also restart the render count
at 0 after every full frame (the display expects that) and keep the count
increment inside the update mutex.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Run the real LcdCommRevC._generate_update_image over many raw lengths
(including those that used to break: 248, 249, 250, 497, 498, 1992 and
~227 KB), for 2.1", 5" and 8" sub-revisions, with a model of the display
packet parsing; check the render count restarts at 0 after a full frame.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
LcdCommRevCVideo extends LcdCommRevC for the 2.1" screen: video storage
(list/size/upload/delete/play) with a size guard that runs before anything is
deleted, full overlay init and incremental overlay updates using the corrected
249-byte framing, status parsing, and serial errors raised as DeviceError so
the caller can back off and reconnect instead of the process exiting.

Port detection and wake-up reuse LcdCommRevC.auto_detect_com_port(). The
existing driver is not modified.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Renders the seamless 8 s / 30 fps loop (navy background, flame ring, sparkles)
and encodes it with ffmpeg, pre-rotated for the screen's native orientation.
The video is re-encoded at a higher CRF until it fits the 1.2 MB storage of the
screen; ffmpeg is checked before use, Popen is cleaned up on errors and no
partial file is left behind. The result is cached in the per-user cache
directory (not the source tree).

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
video-face-rev-c.py runs an animated face on the 2.1" round rev C screen: the
background loops in the screen's own video player and the host only sends small
overlay updates with the CPU / GPU / RAM rows. Sensors come from library/sensors
as selected by HW_SENSORS (GPU shows N/A when unavailable). The loop recovers
from serial errors with backoff and reconnection, refuses unsupported
screens/configs and oversized videos before touching the screen, and exits with
distinct codes for errors that retrying cannot fix.

Tunables live in a new optional video_face section of config.yaml, loaded with
defaults by library/config.py.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Cover status/hello parsing, the video size guard, overlay run/visibility/pixel
encoding and framing, the driver's count handling and recovery with a scripted
serial port, bar colour bands, settings validation, sampler N/A handling and
the video cache / re-encode logic (without ffmpeg or a screen).

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Only a post-upload size mismatch is fatal; serial errors propagate as DeviceError into the reconnect loop. Upload is written in 32 KB chunks with a stop check, errors move to rev_c_errors.py, hello() no longer sleeps after the last attempt.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Guard the video_face config merge, check the stop flag during startup, remove the duplicated build_background, unique temp file for the encoder, ffmpeg stderr to a temp file, cache dir fallback without a home directory.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant